package dtm

import (
	"gitee.com/xuyiping_admin/pkg/apierr"
	"github.com/gin-gonic/gin"
	"kpt-dtm/http/middleware"
	"net/http"
	"strconv"
)

func Dtm(c *gin.Context) {
	path, _ := c.GetQuery("path")
	pastureIdStr, _ := c.GetQuery("pastureId")
	pastureId, _ := strconv.ParseInt(pastureIdStr, 10, 64)
	res, err := middleware.DtmOperation(c).OpsService.Common(c, pastureId, "dtm", path)
	if err != nil {
		apierr.ClassifiedAbort(c, err)
		return
	}
	if res == nil {
		res = gin.H{
			"msg": "ok",
		}
	}
	c.JSON(http.StatusOK, res)
}

func Yyn(c *gin.Context) {
	path, _ := c.GetQuery("path")
	pastureIdStr, _ := c.GetQuery("pastureId")
	pastureId, _ := strconv.ParseInt(pastureIdStr, 10, 64)
	res, err := middleware.DtmOperation(c).OpsService.Common(c, pastureId, "yyn", path)
	if err != nil {
		apierr.ClassifiedAbort(c, err)
		return
	}
	if res == nil {
		res = gin.H{
			"msg": "ok",
		}
	}
	c.JSON(http.StatusOK, res)
}

func Auth(c *gin.Context) {
	path, _ := c.GetQuery("path")
	pastureIdStr, _ := c.GetQuery("pastureId")
	pastureId, _ := strconv.ParseInt(pastureIdStr, 10, 64)
	res, err := middleware.DtmOperation(c).OpsService.Common(c, pastureId, "yyn", path)
	if err != nil {
		apierr.ClassifiedAbort(c, err)
		return
	}
	if res == nil {
		res = gin.H{
			"msg": "ok",
		}
	}
	c.JSON(http.StatusOK, res)
}
